import 'package:get/get_state_manager/get_state_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:shen_nai/app/setting.dart';
//配置信息保存
class UserController extends GetxController {
  String username = '';
  String account = '';
  String password = '';
  int jurisdiction = 0;

  List<String> bit100List = [];
  List<String> bit140List = [];

  UserController() {
    init();
  }

  init() async {
    var sp = await SharedPreferences.getInstance();
    username = sp.getString(Setting.USERNAME) ?? '';
    account = sp.getString(Setting.ACCOUNT) ?? '';
    password = sp.getString(Setting.PASSWORD) ?? '';
    jurisdiction = sp.getInt(Setting.JURISDICTION) ?? 0;
  }

  setBit100List(List<String> list) {
    bit100List = list;
  }

  setBit140List(List<String> list) {
    bit140List = list;
  }

  setUsername(String username) async {
    var sp = await SharedPreferences.getInstance();
    sp.setString(Setting.USERNAME, username);
    this.username = username;
  }

  setJurisdiction(int jurisdiction) async {
    var sp = await SharedPreferences.getInstance();
    sp.setInt(Setting.JURISDICTION, jurisdiction);
    this.jurisdiction = jurisdiction;
  }

  setPassword(String password) async {
    var sp = await SharedPreferences.getInstance();
    sp.setString(Setting.PASSWORD, password);
    this.password = password;
  }

  setAccount(String account) async {
    var sp = await SharedPreferences.getInstance();
    sp.setString(Setting.ACCOUNT, account);
    this.account = account;
  }

  clear() async {
    username = '';
    account = '';
    password = '';
    jurisdiction = 0;
    var sp = await SharedPreferences.getInstance();
    sp.clear();
    update();
  }
}
